function Tests = saveLoadTest()
Tests = functiontests(localfunctions) ;
end


%**************************************************************************


function testWeekly(This) %#ok<*DEFNU>
rng(0);

actDb = struct();
actDb.x = tseries(ww(2000,1):ww(2010,'end'),@rand);
actDb.x = round(100*actDb.x,2);
dbsave(actDb,'testSaveLoad1.csv');

expDb = dbload('testSaveLoad1.csv');
assertEqual(This, actDb.x(:), expDb.x(:)) ;

dbsave(actDb,'testSaveLoad2.csv',Inf, ...
    'dateFormat=','$YYYY-MM-DD');
expDb = dbload('testSaveLoad2.csv', ...
    'dateFormat=','$YYYY-MM-DD','freq=',52);
assertEqual(This, actDb.x(:), expDb.x(:)) ;
end % testMissingObs()


%**************************************************************************


function testSelect(This) %#ok<*DEFNU>
rng(0);

range = qq(2000,1):qq(2010,4);

actDb = struct();
actDb.x = tseries(range,@rand);
actDb.x = round(100*actDb.x,2);
actDb.y = tseries(range,@rand);
actDb.y = round(100*actDb.y,2);
actDb.z = tseries(range,@rand);
actDb.z = round(100*actDb.z,2);
dbsave(actDb,'testSaveLoad1.csv');

actDb = rmfield(actDb,'x');
expDb = dbload('testSaveLoad1.csv','select=',{'y','z'});
assertEqual(This, actDb, expDb) ;
end % testMissingObs()


%**************************************************************************


function testMissingObs(This) %#ok<*DEFNU>
actDbase = dbload('testMissingObs.csv') ;

range = qq(2000,1) : qq(2000,4) ;
expDbase = struct() ;
expDbase.x = tseries(range, [1;2; NaN; NaN]) ;
expDbase.y = tseries(range, [10+10i; NaN+NaN*1i; 30; NaN+0i]) ;
expDbase.z = tseries(range, [100; NaN; 300; 400]) ;

assertEqual(This, actDbase, expDbase) ;
end % testMissingObs()


%**************************************************************************


function testDailyCsv(This)
d = dbload('testDailyCsv.csv', ...
    'dateFormat=', '$M/D/YYYY', ...
    'freq=', 365) ;
actDbase = db2array(d, {'A', 'B', 'C', 'D'}) ;
actDbase(isnan(actDbase)) = 0 ;

expDbase = csvread('testDailyCsv.csv', 1, 1) ;

assertEqual(This, actDbase, expDbase) ;
end % testDailyCsv()

